package com.gewu.bluetoothflow.adapter

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

import com.gewu.bluetoothflow.R
import com.gewu.bluetoothflow.bean.DeviceInfo


class DeviceAdapter (private val mContext: Context, private val list: List<DeviceInfo>) : RecyclerView.Adapter<DeviceAdapter.ViewHolder>() {

    class ViewHolder(view: View) :RecyclerView.ViewHolder(view){
        val name = view.findViewById<TextView>(R.id.tv_name)
        val time = view.findViewById<TextView>(R.id.tv_time)
        val state = view.findViewById<TextView>(R.id.dev_state)
    }

    interface ItemViewClickListener{
        fun itemClick(i:Int)
    }


    private var itemclick :ItemViewClickListener? = null

     fun setOnItemClick(click :ItemViewClickListener){
        itemclick = click
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.list_item,parent,false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val bluetoothDevice = list[position]
        holder.name.text = bluetoothDevice.name
        holder.time.text = "2024/12/25"

        if (itemclick != null){
            holder.itemView.setOnClickListener {
              //  itemclick!!.itemClick(position)
            }
        }


    }





    override fun getItemCount(): Int {
        return list.size
    }


}